package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowOrderDis;
import cn.stylefeng.guns.modular.manager.mapper.FlowOrderDisMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowOrderDisParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowOrderDisResult;
import  cn.stylefeng.guns.modular.manager.service.FlowOrderDisService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 订单优惠明细 服务实现类
 * </p>
 *
 * @author yumker
 * @since 2021-01-14
 */
@Service
public class FlowOrderDisServiceImpl extends ServiceImpl<FlowOrderDisMapper, FlowOrderDis> implements FlowOrderDisService {

    @Override
    public void add(FlowOrderDisParam param){
        FlowOrderDis entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowOrderDisParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowOrderDisParam param){
        FlowOrderDis oldEntity = getOldEntity(param);
        FlowOrderDis newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowOrderDisResult findBySpec(FlowOrderDisParam param){
        return null;
    }

    @Override
    public List<FlowOrderDisResult> findListBySpec(FlowOrderDisParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowOrderDisParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowOrderDisParam param){
        return param.getOrderDisId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowOrderDis getOldEntity(FlowOrderDisParam param) {
        return this.getById(getKey(param));
    }

    private FlowOrderDis getEntity(FlowOrderDisParam param) {
        FlowOrderDis entity = new FlowOrderDis();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
